package com.luo.ai.assistant.etl;

import org.springframework.ai.document.Document;
import org.springframework.ai.document.DocumentTransformer;
import org.springframework.ai.document.MetadataMode;
import org.springframework.ai.model.transformer.SummaryMetadataEnricher;

import java.util.List;

/**
 * 文档转换器
 *
 * @author luohq
 * @date 2025-01-02 8:51
 */
public interface MyDocumentTransformer extends DocumentTransformer {

    /**
     * Split token.
     * <p>
     *     This splitter is particularly useful for preparing text for large language models that have token limits,
     *     ensuring that each chunk is within the model’s processing capacity.
     *     The TokenTextSplitter uses the CL100K_BASE encoding from the jtokkit library, which is compatible with newer OpenAI models.
     * </p>
     *
     * @param documents the documents
     * @return the list
     * @see org.springframework.ai.transformer.splitter.TokenTextSplitter
     */
    List<Document> splitTokens(List<Document> documents);

    /**
     * Split token.
     * <p>
     *     This splitter is particularly useful for preparing text for large language models that have token limits,
     *     ensuring that each chunk is within the model’s processing capacity.
     *     The TokenTextSplitter uses the CL100K_BASE encoding from the jtokkit library, which is compatible with newer OpenAI models.
     * </p>
     * @param documents             the documents
     * @param chunkSize             the chunk size
     * @param minChunkSizeChars     the min chunk size chars
     * @param minChunkLengthToEmbed the min chunk length to embed
     * @param maxNumChunks          the max num chunks
     * @param keepSeparator         the keep separator
     * @return the list
     * @link <a href="https://docs.spring.io/spring-ai/reference/api/etl-pipeline.html#_tokentextsplitter">https://docs.spring.io/spring-ai/reference/api/etl-pipeline.html#_tokentextsplitter</a>
     * @see org.springframework.ai.transformer.splitter.TokenTextSplitter
     */
    List<Document> splitTokens(List<Document> documents,
                               int chunkSize,
                               int minChunkSizeChars,
                               int minChunkLengthToEmbed,
                               int maxNumChunks,
                               boolean keepSeparator);

    /**
     * Enrich keyword metadata（excerpt_keywords）
     *
     * @param documents the documents
     * @return the list
     * @see org.springframework.ai.model.transformer.KeywordMetadataEnricher
     */
    List<Document> enrichKeywordMetadata(List<Document> documents);

    /**
     * Enrich keyword metadata（excerpt_keywords）
     *
     * @param documents    the documents
     * @param keywordCount the keyword count
     * @return the list
     * @see org.springframework.ai.model.transformer.KeywordMetadataEnricher
     */
    List<Document> enrichKeywordMetadata(List<Document> documents, int keywordCount);

    /**
     * Enrich summary metadata（section_summary, prev_section_summary, next_section_summary）
     *
     * @param documents the documents
     * @return the list
     * @see org.springframework.ai.model.transformer.SummaryMetadataEnricher
     */
    List<Document> enrichSummaryMetadata(List<Document> documents);

    /**
     * Enrich summary metadata（section_summary, prev_section_summary, next_section_summary）
     *
     * @param documents       the documents
     * @param summaryTypes    the summary types
     * @param summaryTemplate the summary template
     * @param metadataMode    the metadata mode
     * @return the list
     * @see org.springframework.ai.model.transformer.SummaryMetadataEnricher
     */
    List<Document> enrichSummaryMetadata(List<Document> documents,
                                         List<SummaryMetadataEnricher.SummaryType> summaryTypes,
                                         String summaryTemplate,
                                         MetadataMode metadataMode);

    /**
     * Uniform content.
     *
     * @param documents the documents
     * @return the list
     * @see org.springframework.ai.document.ContentFormatter
     * @see org.springframework.ai.transformer.ContentFormatTransformer
     */
    List<Document> uniformContent(List<Document> documents);

}
